const path = require('path');

const entries = {
    "popup.js": "./Popup/popup.ts",
    "options.js": "./Options/options.ts",
    "contentScript.js": "./ContentScript/contentScript.ts",
    "background.js": "./Background/background.ts"
};

module.exports = {
    mode: "development", // production
    entry: entries, //指定入口文件，程序从这里开始编译,__dirname当前所在目录, ../表示上一级目录, ./同级目录
    output: {
        path: path.resolve(__dirname, 'ChromeExtension'), // 输出的路径
        filename: '[name]'  // 打包后文件
    },
    resolve: {
        extensions: ['.ts', '.js'],
        alias: {
          "@lib": path.resolve(__dirname, "./Lib/")
        },
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [{
                    loader: 'style-loader'
                }, {
                    loader: 'css-loader'
                }]
            },
            {
                test: /\.less$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader'
                    },
                    {
                        loader: 'less-loader'
                    }
                ]
            },
            {
                test: /\.ts?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
            , 
            {
                parser: { amd: false }
            }
        ]
    },

    // watch: true,
    watchOptions: {
      poll: 1000, // 每秒询问多少次
      aggregateTimeout: 500,  //防抖 多少毫秒后再次触发
      ignored: /node_modules/ //忽略时时监听
    },
    devServer: {
        //contentBase: path.join(__dirname, "dist"),
        contentBase: path.join(__dirname, "ChromeExtension"),
        port: 7000,
        //publicPath:'/'
        //overlay: true,
        host: '127.0.0.1',
        progress: true,
        disableHostCheck: true,
        stats: "errors-only",
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
            "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
        }
    }
}